from tokenizer import Tokenizer
from parser import Parser
from formatter import Formatter

datetime_parser = Parser(Tokenizer('''
module 'datetime'
def Date {}
'''))

parser = Parser(Tokenizer('''
module 'demo'
use "datetime"
def Empty {}
def Generic<T:Set<Date>, U> {
    times: T,
    "obj": U
}
def World {}
def Hello : World {
    hello: String?
    _ : Any
}
{
    empty_string: "",
    string: "str",
    empty_string_single: '',
    string_single: 'str',
    escape_string: "\\\\ \\/ \\b \\f \\n \\r \\t \\u0061",
    int: 1,
    float: 2.1,
    neg_int: -1,
    neg_float: -2.1
    ex: 3e2,
    ex_pos: 3e+2,
    ex_neg: 3e-2,
    neg_ex: -3e2,
    neg_ex_pos: -3e+2,
    neg_ex_neg: -3e-2,
    ex_float: 1.3e2,
    ex_float_pos: 1.3e+2,
    ex_float_neg: 1.3e-2,
    neg_ex_float: -1.3e2,
    neg_ex_float_pos: -1.3e+2,
    neg_ex_float_neg: -1.3e-2,
    null_value: null,
    bool_true: true,
    bool_false: false,
    object: {
        hello: "world"
    },
    array: [1,2],
    set: (3,4),
    typed_value: Hello {
        hello: "world"
    },
    generic: Generic<Set<Int>, Float> {
        times: (123),
        obj: 1.23
    }
}
'''.strip()))


def print_parse_res(x):
    print (x['module'])
    print ('\n'.join(str(e) for e in x['use']))
    print ('\n'.join(str(e) for e in x['def']))
    print (x['value'])

res = parser.parse()
print_parse_res(res)

res2 = datetime_parser.parse()
print_parse_res(res2)

formatter = Formatter()
r = formatter.format([res, res2], [])
print (r)
